package com.wink_172

import android.app.Activity
import android.app.Application
import android.content.Intent
import android.os.Bundle
import com.adjust.sdk.Adjust
import com.adjust.sdk.AdjustConfig
import com.adjust.sdk.LogLevel
import com.example.bibuproject.service.AppoperationServiceConnect
import com.example.bibuproject.service.BackgroundService
import com.wink_172.library.LibApplication
import com.wink_172.library.utils.CommonUtils
import com.wink_172.model.Constants
import org.xutils.x

class ABpplication : LibApplication() {

    companion object instance {
        var connect: AppoperationServiceConnect? = null
    }

    override fun onCreate() {
        super.onCreate()

//      CommonUtils.preinitUMeng(this,Constants.UMENG_KEY);
        CommonUtils.initUMeng(this, Constants.UMENG_KEY)

        x.task().postDelayed(kotlinx.coroutines.Runnable {
            CommonUtils.testUMEvent()
        }, 2000)

        startService()
        initAdjust()


        registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks())
//        TencentCosUtils.initTectentCos("","","")
    }

    fun startService() {
        var appServiceIntent = Intent(x.app(), BackgroundService::class.java)
        connect = AppoperationServiceConnect()
        bindService(appServiceIntent, connect!!, BIND_AUTO_CREATE)
    }


    fun initAdjust() {

        val config = AdjustConfig(this, "pd3jbdt563uo", AdjustConfig.ENVIRONMENT_PRODUCTION)
//        config.setFbAppId(fb_app_id_string)
        config.setLogLevel(LogLevel.WARN)
        Adjust.onCreate(config)
    }

    class AdjustLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
        override fun onActivityCreated(p0: Activity, p1: Bundle?) {

        }

        override fun onActivityStarted(p0: Activity) {

        }

        override fun onActivityResumed(activity: Activity) {
            Adjust.onResume()
        }

        override fun onActivityPaused(activity: Activity) {
            Adjust.onPause()
        }

        override fun onActivityStopped(p0: Activity) {

        }

        override fun onActivitySaveInstanceState(p0: Activity, p1: Bundle) {

        }

        override fun onActivityDestroyed(p0: Activity) {

        }
    }
}